package com.tiocloud.chat.feature.session.common.adapter.viewholder;

import android.text.style.ImageSpan;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.tiocloud.chat.R;
import com.tiocloud.chat.feature.session.common.adapter.MsgAdapter;
import com.tiocloud.chat.feature.session.common.adapter.viewholder.base.MsgBaseViewHolder;
import com.tiocloud.chat.util.MoonUtil;

/**
 * author : TaoWang
 * date : 2019-12-30
 * desc : 文本类型消息
 */
public class MsgTextViewHolder extends MsgBaseViewHolder {
    private TextView bodyTextView;

    public MsgTextViewHolder(MsgAdapter adapter) {
        super(adapter);
    }

    @Override
    protected int contentResId() {
        return R.layout.message_item_text;
    }

    @Override
    protected void inflateContent() {
        bodyTextView = findViewById(R.id.tv_message);
    }

    @Override
    protected void bindContent(BaseViewHolder holder) {
        String content = getMessage().getContent();
        if (content == null) content = "";

        // 表情识别
        MoonUtil.identifyFaceExpression(bodyTextView, content, ImageSpan.ALIGN_BOTTOM);
    }

    @Override
    protected View.OnLongClickListener onContentLongClick() {
        return view -> {
            showAttachView(view, getCopyText());
            return true;
        };
    }

    private String getCopyText() {
        if (bodyTextView != null) {
            return bodyTextView.getText().toString();
        }
        return null;
    }

    @Override
    protected boolean isShowContentBg() {
        return true;
    }
}
